//
//  YJMainViewController.swift
//  YJWeiBo
//
//  Created by Jim1024 on 2017/1/10.
//  Copyright © 2017年 Jim1024. All rights reserved.
//

import UIKit

class YJMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // 使用KVC来自定义tabBar
        let newTabBar = YJMainTabBar()
        setValue(newTabBar, forKey: "tabBar")
        
        newTabBar.composeButtonCallback = {() -> () in
            print("点击了中间的按钮")
        }
        
        addchildViewControllers()
    }
    
    private func addchildViewControllers() {
        add(YJHomeViewController(), title: "首页", imageName: "tabbar_home")
        add(YJMessageViewController(), title: "消息", imageName: "tabbar_message_center")
        add(YJDiscoverViewController(), title: "发现", imageName: "tabbar_discover")
        add(YJProfileViewController(), title: "我", imageName: "tabbar_profile")
    }
    

    private func add(_ childController: UIViewController, title: String, imageName: String) {
        childController.title = title
        childController.tabBarItem.image = UIImage(named: imageName)
        
        let hightedImageName = imageName + "_highlighted"
        childController.tabBarItem.selectedImage = UIImage(named: hightedImageName)?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orange], for: UIControlState.normal)

        addChildViewController(UINavigationController(rootViewController: childController))
    }
}
